package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    
    import gs.TweenLite;
    import gs.easing.Cubic;
    import gs.easing.Expo;

    public class FlyingScore extends Sprite
    {
        private static const FLY_DURATION  : Number = 1.0; // sec
        private static const FADE_DURATION : Number = 1.0; // sec
        private static const FLY_X : Number = 50;
        private static const FLY_Y : Number = -150;
        
        private var m_label : TextField;        
        
        public function FlyingScore()
        {
            super();
            configureText();
        }
        
        private function configureText() : void
        {
            var format : TextFormat = new TextFormat("embedCourierNew", 18, 0xFFFFFF, true);
            
            m_label = new TextField();
            m_label.embedFonts        = true;
            m_label.selectable        = false;
            m_label.mouseEnabled      = false;
            m_label.autoSize          = TextFieldAutoSize.LEFT;
            m_label.defaultTextFormat = format;
            
            this.addChild(m_label);
        }
        
        public function setScore(score : Number) : void
        {
            m_label.text = String(score); 
        }
        
        public function fly() : void
        {
            TweenLite.to(m_label, FLY_DURATION, {x:FLY_X, y:FLY_Y, ease:Cubic.easeOut, onComplete:onFlyComplete});
        }
        
        private function onFlyComplete() : void
        {
            TweenLite.to(m_label, FADE_DURATION, {alpha : 0, ease:Expo.easeOut, onComplete:onFadeComplete});
        }
        
        private function onFadeComplete() : void
        {
            parent.removeChild(this);            
        }
    }
}